/*
 * 车牌识别
 * author：戴布斯
 */
//var 是定义变量
var video = document.getElementById("video"); // 获取video标签
var context = canvas.getContext("2d");
var con = {
	audio : false,
	video : true,
	video : {
		width : 1980,
		height : 1024,

	}
};

// 导航 获取用户媒体对象
navigator.mediaDevices.getUserMedia(con).then(function(stream) {
	try {
		video.src = window.URL.createObjectURL(stream);
	} catch (e) {
		video.srcObject = stream;
	}

	video.onloadmetadate = function(e) {
		video.play();
	}
});

function takePhoto() {

	// 把流媒体数据画到convas画布上去
	context.drawImage(video, 0, 0, 530, 300);
	var base = getBase64();
	$.ajax({
		type : "post",
		url : "onAndout",
		data : {
			"base" : base
		},
		dataType : "text",
		success : function(json) {
			console.log(json)
			if (json == "jinru") {
				window.location = "Tip.jsp"
				/* window.location = "Tip.jsp" */
			}else if(json=="youjinru"){
				console.log("原来");
				window.location = "Tip.jsp"
			}else if(json=="chuqu"){
				console.log("支付")
				window.location = "alipayindex2.jsp"
			}
		}
	});

}

function getBase64() {
	var imgSrc = document.getElementById("canvas").toDataURL("image/png");

	return imgSrc.split("base64,")[1];

};